<?php

namespace Admin\Controller;

use Think\Image;
use Think\Upload;

class ConfigController extends PublicController
{
    /**
     * 首页
     */
    public function index()
    {
        $result = M('config')->order("id desc")->find();
        $this->assign('result', $result);
         $this->display();
    }

    /**
     * 修改界面
     */
    public function edit()
    {
        $result = M('config')->order("id desc")->find();
        $this->assign('result', $result);
        $this->display();
    }

    /**
     * 删除
     */
    public function del()
    {
        $id = I('request.id');
        M('config')->where("id='$id'")->delete();
    }

    /**
     * 编辑新增
     */
    public function update()
    {
        $id = I('request.id');
        $agreement = $_POST['agreement'];
        if ($agreement){
            $data['agreement'] = $agreement;
        }
        $data['site'] = I('request.site');
        if ($id) {
            $result = M('config')->where("id='$id'")->save($data);
            if ($result !== false) {
                $this->success("操作成功", 'Admin/Config/index');
            } else {
                $this->error("操作失败");
            }
        } else {
            $result = M('config')->add($data);
//            echo M()->_sql();
            if ($result) {
                $this->success("操作成功", 'Admin/Config/index');
            } else {
                $this->error("操作失败");
            }
        }

    }
}